home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '90 / MacHack'90 Proceedings / John Norstad / Reusable Code / Source / pref.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-10  |  19.8 KB  |  661 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________________________
  2.  
  3.     pref.c - Preferences Window Manager.
  4.     
  5.     Copyright © 1988, 1989, 1990 Northwestern University.  Permission is 
  6.     granted to use this code in your own projects, provided you give credit 
  7.     to both John Norstad and Northwestern University in your about box or 
  8.     document.
  9. _____________________________________________________________________*/
  10.  
  11.  
  12. #pragma load "precompile"
  13. #include "utl.h"
  14. #include "rez.h"
  15. #include "glob.h"
  16. #include "wstm.h"
  17. #include "pref.h"
  18. #include "help.h"
  19.  
  20. #pragma segment pref
  21.  
  22. /*______________________________________________________________________
  23.  
  24.     Global Variables.
  25. _____________________________________________________________________*/
  26.  
  27.  
  28. static WindowPtr            PrefWindow = nil;        /* ptr to prefs window */
  29. static DialogRecord        PrefWRecord;            /* prefs window record */
  30. static WindowObject        PrefWindObject;        /* pref window object */
  31. static MenuHandle            RepMenu = nil;            /* handle to rep creator popup menu */
  32. static MenuHandle            DocMenu = nil;            /* handle to doc creator popup menu */
  33.     
  34. /*______________________________________________________________________
  35.  
  36.     Activate - Process an Activate Event.
  37. _____________________________________________________________________*/
  38.  
  39.  
  40. static void Activate (void)
  41.  
  42. {
  43.     TEActivate(((DialogPeek)PrefWindow)->textH);
  44. }
  45.     
  46. /*______________________________________________________________________
  47.  
  48.     Deactivate - Process a Deactivate Event.
  49. _____________________________________________________________________*/
  50.  
  51.  
  52. static void Deactivate (void)
  53.  
  54. {
  55.     TEDeactivate(((DialogPeek)PrefWindow)->textH);
  56. }
  57.  
  58. /*______________________________________________________________________
  59.  
  60.     Help - Process Mouse Down Event in Help Mode.
  61.     
  62.     Entry:        where = mouse down location, local coords.
  63. _____________________________________________________________________*/
  64.  
  65.  
  66. static void Help (Point where)
  67.  
  68. {
  69.     short                itemType;                /* dialog item type */
  70.     Handle            itemHandle;                /* dialog item handle */
  71.     Rect                box;                        /* dialog item rectangle */
  72.         
  73.     GetDItem(PrefWindow, prefsHorRule1, &itemType, &itemHandle, &box);
  74.     if (where.v < box.top) {
  75.         help_Open(tagPrefBeep);
  76.         return;
  77.     };
  78.     GetDItem(PrefWindow, prefsHorRule2, &itemType, &itemHandle, &box);
  79.     if (where.v < box.top) {
  80.         help_Open(tagPrefStation);
  81.         return;
  82.     };
  83.     GetDItem(PrefWindow, prefsHorRule3, &itemType, &itemHandle, &box);
  84.     if (where.v < box.top) {
  85.         help_Open(tagPrefSave);
  86.         return;
  87.     };
  88.     help_Open(tagPrefNotif);
  89. }
  90.  
  91. /*______________________________________________________________________
  92.  
  93.     Close - Close the Window
  94. _____________________________________________________________________*/
  95.  
  96.  
  97. static void Close (void)
  98.  
  99. {
  100.     Prefs.prefState.moved = PrefWindObject.moved;
  101.     wstm_Save(PrefWindow, &Prefs.prefState);
  102.     CloseDialog(PrefWindow);
  103.     PrefWindow = nil;
  104. }
  105.     
  106. /*______________________________________________________________________
  107.  
  108.     Edit - Process Edit Command.
  109.     
  110.     Entry:    cmd = which Edit command.
  111. _____________________________________________________________________*/
  112.  
  113.  
  114. static void Edit (EditCmd cmd)
  115.  
  116. {
  117.     short                item;                        /* dialog item number */
  118.     TEHandle            textH;                    /* handle to TextEdit record */
  119.     short                selSize;                    /* size of selected part of item */
  120.     short                textLen;                    /* text length */
  121.     long                scrapLen;                /* size of scrap */
  122.     Handle            scrapHandle;            /* handle to scrap */
  123.     char                scrapChar;                /* scrap character */
  124.             
  125.     switch (cmd) {
  126.         case cutCmd:
  127.             DlgCut(PrefWindow);
  128.             ZeroScrap();
  129.             TEToScrap();
  130.             break;
  131.         case copyCmd:
  132.             DlgCopy(PrefWindow);
  133.             ZeroScrap();
  134.             TEToScrap();
  135.             break;
  136.         case pasteCmd:
  137.             TEFromScrap();
  138.             item = ((DialogPeek)PrefWindow)->editField + 1;
  139.             textH = ((DialogPeek)PrefWindow)->textH;
  140.             selSize = (**textH).selEnd - (**textH).selStart;
  141.             textLen = (**textH).teLength;
  142.             scrapLen = TEGetScrapLen();
  143.             if ( item == prefsBeep) {
  144.                 /* Number of beeps field - beep and return if there would 
  145.                     be more than two digits in the field after the paste. */
  146.                 if (textLen + scrapLen - selSize > 2) {
  147.                     SysBeep(beepDuration);
  148.                     return;
  149.                 };
  150.                 /* Beep and return if the scrap contains a non-digit. */
  151.                 scrapHandle = TEScrapHandle();
  152.                 while (scrapLen--) {
  153.                     scrapChar = *(*scrapHandle + scrapLen);
  154.                     if (scrapChar < '0' || scrapChar > '9') {
  155.                         SysBeep(beepDuration);
  156.                         return;
  157.                     };
  158.                 };
  159.             } else {
  160.                 /* File creator type field - beep and return if there would
  161.                     be more than four characters in the field after the paste. */
  162.                 if (textLen + scrapLen - selSize > 4) {
  163.                     SysBeep(beepDuration);
  164.                     return;
  165.                 };
  166.             };
  167.             DlgPaste(PrefWindow);
  168.             break;
  169.         case clearCmd:
  170.             DlgDelete(PrefWindow);
  171.             break;
  172.     };
  173. }    
  174.     
  175. /*______________________________________________________________________
  176.  
  177.     Adjust - Adjust Menus.
  178. _____________________________________________________________________*/
  179.  
  180.  
  181. static void Adjust (void)
  182.  
  183. {
  184.     MenuHandle                fileM;                    /* handle to file menu */
  185.     MenuHandle                editM;                    /* handle to edit menu */
  186.     MenuHandle                scanM;                    /* handle to scan menu */
  187.     MenuHandle                disinfectM;                /* handle to disinfect menu */
  188.     
  189.     fileM = GetMHandle(fileMID);
  190.     editM = GetMHandle(editMID);
  191.     scanM = GetMHandle(scanMID);
  192.     disinfectM = GetMHandle(disinfectMID);
  193.     EnableItem(fileM, closeCommand);
  194.     DisableItem(fileM, saveAsCommand);
  195.     DisableItem(fileM, pageSetupCommand);
  196.     DisableItem(fileM, printCommand);
  197.     DisableItem(fileM, printOneCommand);
  198.     if (Scanning) {
  199.         DisableItem(fileM, quitCommand);
  200.         DisableItem(scanM, 0);
  201.         DisableItem(disinfectM, 0);
  202.     } else {
  203.         EnableItem(fileM, quitCommand);
  204.         EnableItem(scanM, 0);
  205.         EnableItem(disinfectM, 0);
  206.     };
  207.     DisableItem(editM, undoCommand);
  208.     EnableItem(editM, cutCommand);
  209.     EnableItem(editM, copyCommand);
  210.     EnableItem(editM, pasteCommand);
  211.     EnableItem(editM, clearCommand);
  212.     EnableItem(editM, 0);
  213. }
  214.  
  215. /*______________________________________________________________________
  216.  
  217.     DialogPre - Preprocess Dialog Event
  218.     
  219.     Entry:        key = key pressed.
  220.     
  221.     Exit:            function result = true if event should be processed,
  222.                         false if it should be discarded.
  223. _____________________________________________________________________*/
  224.  
  225.  
  226. static Boolean DialogPre (short key)
  227.  
  228. {
  229.     short                item;                        /* dialog item number */
  230.     TEHandle            textH;                    /* handle to TextEdit record */
  231.     short                selSize;                    /* size of selected part of item */
  232.     short                textLen;                    /* text length */
  233.         
  234.     if (key == deleteKey || key == tabKey ||
  235.         key == leftArrow || key == rightArrow) return true;
  236.     item = ((DialogPeek)PrefWindow)->editField + 1;
  237.     textH = ((DialogPeek)PrefWindow)->textH;
  238.     selSize = (**textH).selEnd - (**textH).selStart;
  239.     textLen = (**textH).teLength;
  240.     if (item == prefsBeep) {
  241.         /* Number of beeps field - beep and return false if the key
  242.             is not a digit, or if there would be more than two digits in
  243.             the field after the key is processed. */
  244.         if (key < '0' || key > '9' || textLen + 1 - selSize > 2) {
  245.             SysBeep(beepDuration);
  246.             return false;
  247.         };
  248.     } else {
  249.         /* File creator type field - beep and return false if there would
  250.             be more than four characters in the field after the key is
  251.             processed. */
  252.         if (textLen + 1 - selSize > 4) {
  253.             SysBeep(beepDuration);
  254.             return false;
  255.         };
  256.     };
  257.     return true;
  258. }
  259.  
  260. /*______________________________________________________________________
  261.  
  262.     GetPopInfo - Get Pop Up Menu Info.
  263.     
  264.     Entry:    popItem = item number of popup menu user item.
  265.                 creType = creator type.
  266.     
  267.     Exit:        theMenu = handle to menu.
  268.                 numItems = number of items in menu.
  269.                 creList = handle to creator type list.
  270.                 creIndex = index in menu of application name.
  271. _____________________________________________________________________*/
  272.  
  273.  
  274. static void GetPopInfo (short popItem, OSType creType,
  275.     MenuHandle *theMenu, short *numItems,
  276.     OSType ***creList, short *creIndex)
  277.     
  278. {
  279.     short        inx;                /* index in menu */
  280.  
  281.     if (popItem == prefsRepPop) {
  282.         if (!RepMenu) RepMenu = GetMenu(prefsRepMenuID);
  283.         *creList = (OSType**)GetResource('CREA', prefsRepCreaID);
  284.         *theMenu = RepMenu;
  285.     } else {
  286.         if (!DocMenu) DocMenu = GetMenu(prefsDocMenuID);
  287.         *creList = (OSType**)GetResource('CREA', prefsDocCreaID);
  288.         *theMenu = DocMenu;
  289.     };
  290.     *numItems = CountMItems(*theMenu);
  291.     for (inx = 0; inx < *numItems; inx++) {
  292.         if (creType == *(**creList + inx)) break;
  293.     };
  294.     if (inx < *numItems) inx++;
  295.     *creIndex = inx;
  296. }
  297.  
  298. /*______________________________________________________________________
  299.  
  300.     PopUp - Pop Up Menu.
  301.     
  302.     Entry:    popItem = item number of popup menu user item.
  303.                 labelItem = item number of label static text item.
  304.                 editItem = item number of edittext item.
  305.                 menuID = resource id of popup menu.
  306.                 creType = pointer to Prefs creator type field.
  307.                 otherType = pointer to Prefs other creator type field.
  308. _____________________________________________________________________*/
  309.  
  310.  
  311. static void PopUp (short popItem, short labelItem, short editItem, short menuID,
  312.     OSType *creType, OSType *otherType)
  313.  
  314. {
  315.     MenuHandle        theMenu;                /* handle to menu */
  316.     short                itemType;            /* dialog item type */
  317.     Handle            itemHandle;            /* dialog item handle */
  318.     Rect                labelBox;            /* label rectangle */
  319.     Rect                popBox;                /* popup menu rectangle */
  320.     Rect                typeBox;                /* textedit rectangle */
  321.     Point                popPoint;            /* location of popup menu, global coords */
  322.     long                result;                /* PopUpMenuSelect result */
  323.     OSType            **creList;            /* handle to list of creator types */
  324.     short                numItems;            /* number of items in list */
  325.     short                oldIndex;            /* index in list of old selected item */
  326.     short                newIndex;            /* index in list of new selected item */
  327.     char                itemText[5];        /* creator type */
  328.     
  329.     /* Return if the system does not support popup menus. */
  330.     
  331.     if (!utl_SysHasPopUp()) return;
  332.     
  333.     /* Get popup info. */
  334.     
  335.     GetPopInfo(popItem, *creType, &theMenu, &numItems, &creList, &oldIndex);
  336.     
  337.     /* Check the currently selected item, and invert the label rectangle. */
  338.     
  339.     CheckItem(theMenu, oldIndex, true);
  340.     GetDItem(PrefWindow, labelItem, &itemType, &itemHandle, &labelBox);
  341.     InvertRect(&labelBox);
  342.     
  343.     /* Get the location of the popup menu and convert it to global coords. */
  344.     
  345.     GetDItem(PrefWindow, popItem, &itemType, &itemHandle, &popBox);
  346.     popPoint = *(Point*)&popBox;
  347.     LocalToGlobal(&popPoint);
  348.     
  349.     /* Present the popup menu. */
  350.     
  351.     InsertMenu(theMenu, -1);
  352.     result = PopUpMenuSelect(theMenu, popPoint.v, popPoint.h, oldIndex);
  353.     DeleteMenu(menuID);
  354.     
  355.     /* Uncheck the old selected item, and uninvert the lable rectangle. */
  356.     
  357.     CheckItem(theMenu, oldIndex, false);
  358.     InvertRect(&labelBox);
  359.     
  360.     /* Process the new selected item. */
  361.     
  362.     if ((result >> 16) & 0xffff) {
  363.         GetDItem(PrefWindow, editItem, &itemType, &itemHandle, &typeBox);
  364.         newIndex = (result & 0xffff);
  365.         if (oldIndex == numItems) {
  366.             GetIText(itemHandle, itemText);
  367.             *otherType = '    ';
  368.             memcpy(otherType, itemText+1, *itemText);
  369.         };
  370.         if (newIndex == numItems) {
  371.             *creType = *otherType;
  372.         } else {
  373.             *creType = *(*creList + newIndex - 1);
  374.         };
  375.         memcpy(itemText+1, creType, 4);
  376.         *itemText = 4;
  377.         SetIText(itemHandle, itemText);
  378.         InvalRect(&popBox);
  379.     };
  380. }
  381.  
  382. /*______________________________________________________________________
  383.  
  384.     DialogPost - Postprocess Dialog Event
  385.     
  386.     Entry:        item = dialog item number.
  387. _____________________________________________________________________*/
  388.  
  389.  
  390. static void DialogPost (short item)
  391.  
  392. {
  393.     short                itemType;                /* dialog item type */
  394.     Handle            itemHandle;                /* dialog item handle */
  395.     Rect                box;                        /* dialog item rectangle */
  396.     char                itemText[5];            /* dialog item text */
  397.     long                beepCount;                /* beep count */
  398.         
  399.     switch (item) {
  400.         case prefsBeep:
  401.             GetDItem(PrefWindow, prefsBeep, &itemType, &itemHandle, &box);
  402.             GetIText(itemHandle, itemText);
  403.             StringToNum(itemText, &beepCount);
  404.             Prefs.beepCount = beepCount;
  405.             break;
  406.         case prefsStation:
  407.             Prefs.scanningStation = !Prefs.scanningStation;
  408.             GetDItem(PrefWindow, prefsStation, &itemType, &itemHandle, &box);
  409.             SetCtlValue((ControlHandle)itemHandle, Prefs.scanningStation);
  410.             GetDItem(PrefWindow, prefsScan, &itemType, &itemHandle, &box);
  411.             HiliteControl((ControlHandle)itemHandle, 
  412.                 Prefs.scanningStation ? 0 : 255);
  413.             GetDItem(PrefWindow, prefsDisinfect, &itemType, &itemHandle, &box);
  414.             HiliteControl((ControlHandle)itemHandle, 
  415.                 Prefs.scanningStation ? 0 : 255);
  416.             break;
  417.         case prefsScan:
  418.         case prefsDisinfect:
  419.             GetDItem(PrefWindow, prefsScan + Prefs.scanningStationOp,
  420.                 &itemType, &itemHandle, &box);
  421.             SetCtlValue((ControlHandle)itemHandle, 0);
  422.             Prefs.scanningStationOp = item - prefsScan;
  423.             GetDItem(PrefWindow, item, &itemType, &itemHandle, &box);
  424.             SetCtlValue((ControlHandle)itemHandle, 1);
  425.             break;
  426.         case prefsRepPop:
  427.             PopUp(prefsRepPop, prefsRepLabel, prefsRepType, prefsRepMenuID,
  428.                 &Prefs.repCreator, &Prefs.repOtherCre);
  429.             break;
  430.         case prefsDocPop:
  431.             PopUp(prefsDocPop, prefsDocLabel, prefsDocType, prefsDocMenuID,
  432.                 &Prefs.docCreator, &Prefs.docOtherCre);            
  433.             break;
  434.         case prefsRepType:
  435.             GetDItem(PrefWindow, prefsRepType, &itemType, &itemHandle, &box);
  436.             GetIText(itemHandle, itemText);
  437.             Prefs.repCreator = '    ';
  438.             memcpy(&Prefs.repCreator, itemText+1, *itemText);
  439.             GetDItem(PrefWindow, prefsRepPop, &itemType, &itemHandle, &box);
  440.             InvalRect(&box);
  441.             break;
  442.         case prefsDocType:
  443.             GetDItem(PrefWindow, prefsDocType, &itemType, &itemHandle, &box);
  444.             GetIText(itemHandle, itemText);
  445.             Prefs.docCreator = '    ';
  446.             memcpy(&Prefs.docCreator, itemText+1, *itemText);
  447.             GetDItem(PrefWindow, prefsDocPop, &itemType, &itemHandle, &box);
  448.             InvalRect(&box);
  449.             break;
  450.         case prefsDiamond:
  451.         case prefsIcon:
  452.         case prefsAlert:
  453.             GetDItem(PrefWindow, prefsDiamond + Prefs.notifOption,
  454.                 &itemType, &itemHandle, &box);
  455.             SetCtlValue((ControlHandle)itemHandle, 0);
  456.             Prefs.notifOption = item - prefsDiamond;
  457.             GetDItem(PrefWindow, item, &itemType, &itemHandle, &box);
  458.             SetCtlValue((ControlHandle)itemHandle, 1);
  459.             break;
  460.     };
  461. }
  462.  
  463. /*______________________________________________________________________
  464.  
  465.     DrawPopUp - Draw PopUp User Item.
  466.     
  467.     Entry:        theWindow = pointer to dialog window.
  468.                     itemNo = item number.
  469. _____________________________________________________________________*/
  470.  
  471.  
  472. static pascal void DrawPopUp (WindowPtr theWindow, short itemNo)
  473.  
  474. {
  475.     MenuHandle    theMenu;                /* handle to menu */
  476.     short            itemType;            /* item type */
  477.     Handle        itemHandle;            /* item handle */
  478.     Rect            box;                    /* item rectangle */
  479.     OSType        **creList;            /* handle to list of creator types */
  480.     short            numItems;            /* number of items in list */
  481.     short            creIndex;            /* index in list of selected item */
  482.     Str255        appName;                /* application name */
  483.     PolyHandle    triangle;            /* handle to triangle polygon */
  484.     
  485.     /* Get the currently selected application name. */
  486.     
  487.     GetPopInfo(itemNo, 
  488.         itemNo == prefsRepPop ? Prefs.repCreator : Prefs.docCreator, 
  489.         &theMenu, &numItems, &creList, &creIndex);
  490.     GetItem(theMenu, creIndex, appName);
  491.     
  492.     /* Draw the currently selected application name. */
  493.     
  494.     GetDItem(theWindow, itemNo, &itemType, &itemHandle, &box);
  495.     box.left += 4;
  496.     TextBox(appName+1, *appName, &box, teJustLeft);
  497.     box.left -= 4;
  498.  
  499.     /* Frame the rectangle and draw the drop shadow and triangle. */
  500.  
  501.     if (utl_SysHasPopUp()) {
  502.         InsetRect(&box, -1, -1);
  503.         FrameRect(&box);
  504.         MoveTo(box.right, box.top+2);
  505.         LineTo(box.right, box.bottom);
  506.         LineTo(box.left+2, box.bottom);
  507.         triangle = OpenPoly();
  508.         MoveTo(box.right - 14, (box.top + box.bottom - 5)>>1);
  509.         Line(10, 0);
  510.         Line(-5, 5);
  511.         Line(-5, -5);
  512.         ClosePoly();
  513.         PaintPoly(triangle);
  514.         KillPoly(triangle);
  515.     };
  516. }
  517.  
  518. /*______________________________________________________________________
  519.  
  520.     DimNotif - Dim Notificiation Section User Item.
  521.     
  522.     Entry:        theWindow = pointer to dialog window.
  523.                     itemNo = item number.
  524.                     
  525.     If the system does not support the Notification Manager, this user
  526.     item dims the entire section.
  527. _____________________________________________________________________*/
  528.  
  529.  
  530. static pascal void DimNotif (WindowPtr theWindow, short itemNo)
  531.  
  532. {
  533. #pragma unused (itemNo)
  534.  
  535.     short            itemType;            /* item type */
  536.     Handle        itemHandle;            /* item handle */
  537.     Rect            box;                    /* item rectangle */
  538.     
  539.     if (!utl_SysHasNotMgr()) {
  540.         PenMode(patBic);
  541.         PenPat(qd.gray);
  542.         GetDItem(theWindow, prefsNotPict, &itemType, &itemHandle, &box);
  543.         PaintRect(&box);
  544.         GetDItem(theWindow, prefsNotTitle1, &itemType, &itemHandle, &box);
  545.         PaintRect(&box);
  546.         GetDItem(theWindow, prefsNotTitle2, &itemType, &itemHandle, &box);
  547.         PaintRect(&box);
  548.         GetDItem(theWindow, prefsNotTitle3, &itemType, &itemHandle, &box);
  549.         PaintRect(&box);
  550.         PenMode(patCopy);
  551.         PenPat(qd.black);
  552.     };
  553. }
  554.     
  555. /*______________________________________________________________________
  556.  
  557.     pref_Open - Open Pref Window.
  558. _____________________________________________________________________*/
  559.  
  560.  
  561. void pref_Open (void)
  562.  
  563. {
  564.     short                i;                    /* loop index */
  565.     short                itemType;        /* dialog item type */
  566.     Handle            itemHandle;                /* dialog item handle */
  567.     Rect                box;                /* dialog item rectangle */
  568.     char                itemText[5];    /* dialog item text */
  569.     
  570.     /* If the window is already open, activate it. */
  571.     
  572.     if (PrefWindow) {
  573.         SelectWindow(PrefWindow);
  574.         return;
  575.     };
  576.     
  577.     /* Get the pref window and restore its state. */
  578.     
  579.     PrefWindow = wstm_Restore(true, prefsWindID, (Ptr)&PrefWRecord,
  580.         &Prefs.prefState);
  581.     SetPort(PrefWindow);
  582.     
  583.     /* Initialize the window object. */
  584.     
  585.     ((WindowPeek)PrefWindow)->refCon = (long)&PrefWindObject;
  586.     PrefWindObject.windKind = prefWind;
  587.     PrefWindObject.moved = Prefs.prefState.moved;
  588.     PrefWindObject.update = nil;
  589.     PrefWindObject.activate = Activate;
  590.     PrefWindObject.deactivate = Deactivate;
  591.     PrefWindObject.click = nil;
  592.     PrefWindObject.help = Help;
  593.     PrefWindObject.grow = nil;
  594.     PrefWindObject.zoom = nil;
  595.     PrefWindObject.key = nil;
  596.     PrefWindObject.close = Close;
  597.     PrefWindObject.disk = nil;
  598.     PrefWindObject.save = nil;
  599.     PrefWindObject.pageSetup = nil;
  600.     PrefWindObject.print = nil;
  601.     PrefWindObject.edit = Edit;
  602.     PrefWindObject.adjust = Adjust;
  603.     PrefWindObject.periodic = nil;
  604.     PrefWindObject.dialogPre = DialogPre;
  605.     PrefWindObject.dialogPost = DialogPost;
  606.     
  607.     /* Set the pointers to the user item handlers. */
  608.     
  609.     for (i = prefsFirstRule; i <= prefsLastRule; i++) {
  610.         GetDItem(PrefWindow, i, &itemType, &itemHandle, &box);
  611.         SetDItem(PrefWindow, i, itemType, (Handle)utl_FrameItem, &box);
  612.     };
  613.     GetDItem(PrefWindow, prefsRepPop, &itemType, &itemHandle, &box);
  614.     SetDItem(PrefWindow, prefsRepPop, itemType, (Handle)DrawPopUp, &box);
  615.     GetDItem(PrefWindow, prefsDocPop, &itemType, &itemHandle, &box);
  616.     SetDItem(PrefWindow, prefsDocPop, itemType, (Handle)DrawPopUp, &box);
  617.     GetDItem(PrefWindow, prefsDim, &itemType, &itemHandle, &box);
  618.     SetDItem(PrefWindow, prefsDim, itemType, (Handle)DimNotif, &box);
  619.     
  620.     /* Initialize the control values and hilite states. */
  621.     
  622.     GetDItem(PrefWindow, prefsStation, &itemType, &itemHandle, &box);
  623.     SetCtlValue((ControlHandle)itemHandle, Prefs.scanningStation);
  624.     if (utl_SysHasNotMgr()) {
  625.         GetDItem(PrefWindow, prefsDiamond + Prefs.notifOption, 
  626.             &itemType, &itemHandle, &box);
  627.         SetCtlValue((ControlHandle)itemHandle, 1);
  628.     } else {
  629.         for (i = prefsDiamond; i <= prefsAlert; i++) {
  630.             GetDItem(PrefWindow, i, &itemType, &itemHandle, &box);
  631.             HiliteControl((ControlHandle)itemHandle, 255);
  632.         };
  633.     };
  634.     GetDItem(PrefWindow, prefsScan, &itemType, &itemHandle, &box);
  635.     SetCtlValue((ControlHandle)itemHandle, 
  636.         Prefs.scanningStationOp == checkOp);
  637.     if (!Prefs.scanningStation) HiliteControl((ControlHandle)itemHandle, 255);
  638.     GetDItem(PrefWindow, prefsDisinfect, &itemType, &itemHandle, &box);
  639.     SetCtlValue((ControlHandle)itemHandle, 
  640.         Prefs.scanningStationOp == disinfectOp);
  641.     if (!Prefs.scanningStation) HiliteControl((ControlHandle)itemHandle, 255);
  642.     
  643.     /* Initialize the textedit fields. */
  644.     
  645.     GetDItem(PrefWindow, prefsRepType, &itemType, &itemHandle, &box);
  646.     memcpy(itemText+1, &Prefs.repCreator, 4);
  647.     *itemText = 4;
  648.     while (*(itemText + *itemText) == ' ') (*itemText)--;
  649.     SetIText(itemHandle, itemText);
  650.     GetDItem(PrefWindow, prefsDocType, &itemType, &itemHandle, &box);
  651.     memcpy(itemText+1, &Prefs.docCreator, 4);
  652.     *itemText = 4;
  653.     SetIText(itemHandle, itemText);
  654.     GetDItem(PrefWindow, prefsBeep, &itemType, &itemHandle, &box);
  655.     NumToString(Prefs.beepCount, itemText);
  656.     SetIText(itemHandle, itemText);
  657.     
  658.     /* Show the window. */
  659.     
  660.     ShowWindow(PrefWindow);
  661. }